#region <!--##session BUZWholeClass##-->
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		codeGeneratorVariable_DisplayCode.Append(GeneralUsing() + Environment.NewLine);
		##-->*/
namespace <!--##=RepositoryManager.Instance.Repository.ProjectName##-->.BusinessObjects.<!--##=accessorName##-->
{
	public partial class <!--##=className##-->:BusinessObject<!--##=iUserImplement##--><!--##=iRoleImplement##-->
	{
		/*<!--##
		 codeGeneratorVariable_DisplayCode.Append(BUZStatics() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BUZMembers() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BUZStaticMethods() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BUZCustomCode() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BUZDataTableRelatedMethods() + Environment.NewLine);
		##-->*/

		/*<!--##
		if(isUserLoginClass)
		{
		##-->*/
		#region IUser Members

		bool IUser.ChangePassword(string currentPassword, string newPassword)
		{
			if (!string.IsNullOrEmpty(currentPassword))
			{
				//need to validate current password
				if (!DataEncryptor.Instance.GetDecryptedString(this.<!--##=StringProcessor.Property(userLogin.PasswordField)##-->).Equals(currentPassword))
				{
					//validation faied.
					return false;
				}
			}
            
			//now change password.
			this.<!--##=StringProcessor.Property(userLogin.PasswordField)##--> = DataEncryptor.Instance.GetEncryptedString(newPassword);
			this.Save();
			return true;
		}


		private IRole defaultRole = null;
		IRole IUser.DefaultRole
		{
			get
			{
				/*<!--##
				string defaultRoleId="string.Empty";
				string breakAfterFirstItration="break";
				if(userLogin.DefaultRoleIdField!=string.Empty)
				{
					defaultRoleId= string.Format("Convert.ToString(this.{0})",
						StringProcessor.Property(userLogin.DefaultRoleIdField));
					breakAfterFirstItration = string.Empty;	
				}
				##-->*/
				
				
				if (defaultRole == null)
				{
					string defaultRoleId = <!--##=defaultRoleId##-->;
					bool firstRole = true;
					foreach (IRole role in ((IUser)this).Roles)
					{
						if (firstRole)
						{
							//first role is considered default if 'DefaultRole' is not defined.
							defaultRole = role;
							firstRole = false;
							if(string.IsNullOrEmpty(defaultRoleId))
							{
								break;
							}
						}
						if (role.RoleId.Equals(defaultRoleId))
						{
							//defautl role if is defined.
							defaultRole = role;
							break;
						}
					}
				}
				return defaultRole;


				
			}
		}

		bool IUser.IsUserAuthorizedForModule(string key)
		{
			foreach (IRole role in ((IUser)this).Roles)
			{
				if (role.IsUserAuthorizedForModule(key))
				{
					return true;
				}
			}
			return false;

		}

		private IRole[] roles; 
		IRole[] IUser.Roles
		{
			get
			{
				if (roles == null)
				{
					List<IRole> lRoles = new List<IRole>();
					foreach (<!--##=users_rolesClass##--> userRole in Children_<!--##=users_rolesClass##-->.GetBusinessObjects())
					{
						IRole role = userRole.Parent_<!--##=roleClass##-->; 
						lRoles.Add(role);
					}
					roles = lRoles.ToArray();
				}
				return roles;


			}
		}

		string IUser.UserName
		{
			get
			{
				return this.<!--##=StringProcessor.Property(userLogin.UserNameField)##-->;
			}
		}

		string IUser.UserId
		{
			get
			{
				return  Convert.ToString(this.<!--##=StringProcessor.Property(userLogin.UserIdField)##-->);
			}
		}
 

		#endregion

		/*<!--##
		}
		else if (isUserRoleClass)
		{
		##-->*/
		#region IRole Members

		string IRole.HomeModule
		{
			get
			{
				/*<!--##
				if (userRole.homeModuleIdField != string.Empty)
				{
				##-->*/
				return Convert.ToString(this.<!--##=StringProcessor.Property(userRole.homeModuleIdField)##-->); 
				/*<!--##
				}
				else
				{
				##-->*/
				return string.Empty; 
				/*<!--##
				}
				##-->*/
			}
		}

		private Dictionary<string, string> modules;
		bool IRole.IsUserAuthorizedForModule(string key)
		{
			if (modules == null)
			{
				modules=new Dictionary<string,string>();
				foreach (<!--##=roles_modulesClass##-->Paper relatedModule in this.Children_<!--##=roles_modulesClass##-->.GetBOPapers())
				{
					string strModule = Convert.ToString(relatedModule.<!--##=StringProcessor.Property(userRole.moduleIdField)##-->);
					modules.Add(strModule, strModule);
				}
			}

			return modules.ContainsKey(key);
            
		}

		string IRole.RoleName
		{
			get 
			{
				return this.<!--##=StringProcessor.Property(userRole.roleNameField)##-->;
			}
		}

		string IRole.RoleId
		{
			get
			{
				return Convert.ToString(this.<!--##=StringProcessor.Property(userRole.roleIdField)##-->);
			}
		}

		#endregion

		/*<!--##
		}
		##-->*/
	}

	public partial class <!--##=className##-->Paper:BusinessObjectPaper
	{
		/*<!--##
			codeGeneratorVariable_DisplayCode.Append(BUZPaperMembers() + Environment.NewLine);
		##-->*/
	}
}
	
<!--##/session##-->
#endregion

#region <!--##session BUZStatics##-->
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Bussiness Object Statics
		internal readonly static FieldInfoCollection FIELDS=CreateFieldInfoCollection();
		internal readonly static BusinessObjectRelationCollection CHILD_RELATIONS=CreateChildRelations();
		internal readonly static BusinessObjectRelationCollection PARENT_RELATIONS=CreateParentRelations();
		internal readonly static Hashtable DEFAULT_VALUES=PopulateHashtableWithDefaultValues();	
		public partial class FieldNames
		{	
		/*<!--##
        foreach(string entityFieldKey in entity.Fields.Keys)
        {
            Entity.Field entityField = entity.Fields[entityFieldKey];
            <%@EntityFieldIncludes%> 
		##-->*/
            public const string <!--##=entityFieldConstant##--> = "<!--##=entityFieldName##-->";
		/*<!--##
        }
		##-->*/
		}
        public static <!--##=collectionName##--> Collection
		{
			get
			{
				return <!--##=collectionName##-->.Instance;
			}
		}
		public static <!--##=collectionName##--> NewCollection
		{
			get
			{
				return <!--##=collectionName##-->.NewInstance;
			}
		}
        #endregion


<!--##/session##-->
#endregion

#region <!--##session BUZStaticMethods##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Static Methods
		internal static FieldInfoCollection  CreateFieldInfoCollection()
		{
			FieldInfoCollection fields=new FieldInfoCollection(DATATABLE_NAME,TABLE_NAME,VIEW_NAME);
			/*<!--##
			foreach(string entityFieldKey in entity.Fields.Keys)
			{
				Entity.Field entityField = entity.Fields[entityFieldKey];
				<%@EntityFieldIncludes%> 
			##-->*/		
				fields.Add(FieldNames.<!--##=entityFieldConstant##-->,
					new FieldInfo(FieldNames.<!--##=entityFieldConstant##-->,"<!--##=dataType##-->",<!--##=isKey.ToString().ToLower()##-->,
						<!--##=isUnique.ToString().ToLower()##-->,"<!--##=tokenId##-->",<!--##=autoIncreament.ToString().ToLower()##-->,<!--##=isNative.ToString().ToLower()##-->,
						<!--##=isRange.ToString().ToLower()##-->));
			/*<!--##
			}
			##-->*/	
			return fields;	
			
		}
		protected static BusinessObjectRelationCollection CreateChildRelations()
		{
			if(CHILD_RELATIONS != null) return CHILD_RELATIONS;
			BusinessObjectRelationCollection relations=new BusinessObjectRelationCollection();
			
			/*<!--##
			if(entity.Children.Keys.Count > 0)
			{
			##-->*/
			string[] nativeFields,referencedFields;
			/*<!--##
			}
			##-->*/

    		/*<!--##
			foreach(string childrenKey in  entity.Children.Keys)
			{   
				Entity.Relation relation = entity.Children[childrenKey];
				<%@RelationIncludes%> 
			##-->*/
			//Relation [<!--##=childRelationName##-->]
			nativeFields=new string[<!--##=relation.NativeKey.Length##-->];
            referencedFields=new string[<!--##=relation.NativeKey.Length##-->];
				/*<!--##
				for(int i=0; i<relation.NativeKey.Length;  i++)
				{
				##-->*/
            nativeFields[<!--##=i##-->]="<!--##=relation.NativeKey[i].Name##-->";referencedFields[<!--##=i##-->]="<!--##=relation.ReferencedKey[i].Name##-->";
                /*<!--##
			    }
			    ##-->*/

            relations.Add("<!--##=relation.ReferencedEntityName##-->",
				new BusinessObjectRelation("<!--##=childRelationName##-->",
					DATATABLE_NAME,nativeFields,
                    "<!--##=relation.ReferencedEntityName##-->",referencedFields));
			/*<!--##
			}
			##-->*/
			return relations;
		}
		protected static BusinessObjectRelationCollection CreateParentRelations()
		{
			if(PARENT_RELATIONS != null) return PARENT_RELATIONS;
			BusinessObjectRelationCollection relations=new BusinessObjectRelationCollection();
			/*<!--##
			if(entity.Parents.Keys.Count > 0)
			{
			##-->*/
			string[] nativeFields,referencedFields;
			/*<!--##
			}
			##-->*/
            
            /*<!--##
			foreach(string parentsKey in  entity.Parents.Keys)
			{   
				Entity.Relation relation = entity.Parents[parentsKey];
				<%@RelationIncludes%> 
			##-->*/
				//Relation [<!--##=parentRelationName##-->]
			    nativeFields=new string[<!--##=relation.NativeKey.Length##-->];
                referencedFields=new string[<!--##=relation.NativeKey.Length##-->];
				/*<!--##
				for(int i=0; i<relation.NativeKey.Length;  i++)
				{
				##-->*/
                nativeFields[<!--##=i##-->]="<!--##=relation.NativeKey[i].Name##-->";
                referencedFields[<!--##=i##-->]="<!--##=relation.ReferencedKey[i].Name##-->";
                /*<!--##
			    }
			    ##-->*/
                relations.Add("<!--##=relation.ReferencedEntityName##-->",
                    new BusinessObjectRelation("<!--##=parentRelationName##-->",
                        DATATABLE_NAME,nativeFields,
                        "<!--##=relation.ReferencedEntityName##-->",referencedFields));
			/*<!--##
			}
			##-->*/
			return relations;
		}
		/*<!--##
		if(keySignature != string.Empty)
		{
		##-->*/
		public static <!--##=className##--> Get<!--##=className##-->ByKey(<!--##=keySignature##-->)
		{
			
			<!--##=collectionName##--> col = <!--##=collectionName##-->.NewInstance;
			/*<!--##
			foreach(Entity.Field entityField in entity.PrimaryKey)
			{   
				<%@EntityFieldIncludes%> 
			##-->*/
			col.<!--##=property##-->=<!--##=entityFieldVariable##-->;
			/*<!--##
			}
			##-->*/
			return col.BusinessObject;
			
		}
		/*<!--##
			}
		##-->*/

		public static  <!--##=className##--> CreateNewBusinessObject()
		{
			
			return <!--##=collectionName##-->.Instance.CreateNewBusinessObject(); 
			
		}
        #endregion


<!--##/session##-->
#endregion

#region <!--##session BUZDataTableRelatedMethods##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region DataTable Related Methods.
		public static <!--##=className##-->DataTable GetDataTable(DataSet ds)
		{
			return (<!--##=className##-->DataTable)ds.Tables[DATATABLE_NAME];
		}
		
		public static <!--##=className##-->DataTable FillDataTable(DataSet ds)
		{
			return Collection.FillDataTable(ds);
		}
		public static <!--##=className##-->DataTable FillDataTable()
		{
			return Collection.FillDataTable();
		}
		
		public static void UpdateDataTable(DataTable dt)
		{
			Collection.UpdateDataTable(dt,false);
		}
		public static void UpdateDataTable(DataTable dt,bool bTransationBased)
		{
			Collection.UpdateDataTable(dt,bTransationBased);
		}
		  
        #endregion


<!--##/session##-->
#endregion

#region <!--##session BUZMembers##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Members.
		//**Construtors
		
		//For current row with data accessor
		public <!--##=className##-->(BusinessObjectPaper boPaper ,DataAccessor da):base(boPaper,da){}
		
		//For current row with connectionId
		public <!--##=className##-->(BusinessObjectPaper boPaper ,string strConnectionId):base(boPaper,strConnectionId){}
		
		//For current row with default connection
		public <!--##=className##-->(BusinessObjectPaper boPaper):base(boPaper,CONNECTION_ID){}
		
		
		//For new row with default connection 
		public  <!--##=className##-->():base(CONNECTION_ID){}
		
		//For new row with given connection 
		public <!--##=className##-->(string strConnectionId):base(strConnectionId){}
		
   		
		//**Methods
		


		//**Overridden Members
		protected override void RefreshCache()
		{
			S_RefreshCache();
		}
		protected override FieldInfoCollection GetFieldInfoCollection()
		{
			return FIELDS;
		}
		protected override BusinessObjectRelationCollection ChildRelations
		{
			get
			{
				return CHILD_RELATIONS;
			}
		}
		protected override BusinessObjectRelationCollection ParentRelations
		{
			get
			{
				return PARENT_RELATIONS;
			}
		}
		protected override string Table_Name
		{
			get
			{
				return TABLE_NAME;
			}
		}
		protected override string View_Name
		{
			get
			{
				return VIEW_NAME;
			}
		}
		protected override string DataTable_Name
		{
			get
			{
				return <!--##=className##-->.DATATABLE_NAME;
			}
		}
		protected override void PopulateWithCommandCreators(ref CommandCreatorHandler selectCmdCreator,
			ref CommandCreatorHandler updateCmdCreator,
			ref CommandCreatorHandler insertCmdCreator,
			ref CommandCreatorHandler deleteCmdCreator)
		{
			//can be used later.
			selectCmdCreator = null; //new CommandCreatorHandler(Create_SelectIDbCommand);
			updateCmdCreator = null; //new CommandCreatorHandler(Create_UpdateIDbCommand);
			insertCmdCreator = null; //new CommandCreatorHandler(Create_InsertIDbCommand);
			deleteCmdCreator = null; //new CommandCreatorHandler(Create_DeleteIDbCommand);
		}



		//**Properties
		/*<!--##
		foreach(string entityFieldKey in entity.Fields.Keys)
		{
			Entity.Field entityField = entity.Fields[entityFieldKey];
			<%@EntityFieldIncludes%>
			string strNullable = (isValueType)? "?": string.Empty; 
		##-->*/
		public <!--##=cSharpKeywordDataType##--><!--##=strNullable##--> <!--##=property##-->
		{
			get
			{
			/*<!--##
			if(isValueType)
			{
			##-->*/
				object obj = this[FieldNames.<!--##=entityFieldConstant##-->];
				return (obj != null)?
					(<!--##=cSharpKeywordDataType##-->?)Convert.To<!--##=cSharpFrameworkDataType##-->(obj):
					null;
			/*<!--##
			}
			else
			{
			##-->*/
				object obj = this[FieldNames.<!--##=entityFieldConstant##-->];
				return (obj != null)?
					obj as <!--##=cSharpKeywordDataType##-->:
					null;
			/*<!--##
			}
			##-->*/
			}
			
			/*<!--##
			if(isNative && !tokenEnabled && !autoIncreament )
			{
			##-->*/
			
			set
			{
				this[FieldNames.<!--##=entityFieldConstant##-->]= value;
			}
			/*<!--##
			}
			##-->*/
		}
			
		/*<!--##
		}
		##-->*/	
				
		#region Relational Properties
		
		#region Children
		/*<!--##
		foreach(string relKey in  entity.Children.Keys)
		{   
			Entity.Relation relation = entity.Children[relKey];
			<%@RelationIncludes%>
			Entity refEntity = relation.ReferencedEntity;
			<%@RefEntityIncludes%>
		##-->*/
		//<!--##=refEntityName##-->
		public <!--##=refCollectionName##--> Children_<!--##=refClassName##-->
		{
			get
			{
				<!--##=refCollectionName##--> colRef=<!--##=refCollectionName##-->.Instance;
			/*<!--##
			for(int i=0; i<relation.NativeKey.Length;  i++)
			{
				Entity.Field entityField = relation.NativeKey[i];
				Entity.Field refEntityField = relation.ReferencedKey[i];
				<%@EntityFieldIncludes%>
				<%@RefEntityFieldIncludes%>				
			##-->*/
				colRef.<!--##=refProperty##-->=<!--##=property##-->;
			/*<!--##
			}
			##-->*/
				return colRef;
			}
		}
   		public <!--##=refClassName##--> CreateNewChild_<!--##=refClassName##-->()
		{
			<!--##=refClassName##--> boNew=<!--##=refClassName##-->.CreateNewBusinessObject();
			/*<!--##
			for(int i=0; i<relation.NativeKey.Length;  i++)
			{
				Entity.Field entityField = relation.NativeKey[i];
				Entity.Field refEntityField = relation.ReferencedKey[i];
				<%@EntityFieldIncludes%>
				<%@RefEntityFieldIncludes%>				
			##-->*/
			boNew.<!--##=refProperty##-->=<!--##=property##-->;
			/*<!--##
			}
			##-->*/
			return boNew;
		}
		/*<!--##
		}
		##-->*/
		#endregion
		
		#region Parents
		/*<!--##
		foreach(string relKey in  entity.Parents.Keys)
		{   
			Entity.Relation relation = entity.Parents[relKey];
			<%@RelationIncludes%>
			Entity refEntity = relation.ReferencedEntity;
			<%@RefEntityIncludes%>
		##-->*/
		//<!--##=refEntityName##-->
		public <!--##=refClassName##--> Parent_<!--##=refClassName##-->
		{
			get
			{
				<!--##=refCollectionName##--> colRef=<!--##=refCollectionName##-->.Instance;
			/*<!--##
			for(int i=0; i<relation.NativeKey.Length;  i++)
			{
				Entity.Field entityField = relation.NativeKey[i];
				Entity.Field refEntityField = relation.ReferencedKey[i];
				<%@EntityFieldIncludes%>
				<%@RefEntityFieldIncludes%>				
			##-->*/
				colRef.<!--##=refProperty##-->=<!--##=property##-->;
			/*<!--##
			}
			##-->*/
				return colRef.BusinessObject;
			}
			
		}
		/*<!--##
		}
		##-->*/
   		
		#endregion

		#endregion
		

		public override object this[string fieldName]
		{
			get
			{
				object obj = base[fieldName];
				return (obj == DBNull.Value || obj == null)?
					 <!--##=className##-->.DEFAULT_VALUES[fieldName]:
					 obj;
			}
			set
			{
				base[fieldName]= value;
			}
		}	

		#endregion


<!--##/session##-->
#endregion

#region <!--##session BUZCustomCode##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
		//user code should be written under the following region, otherwise code will not be safe.
		/** Custom Region Start [Code Generator] **/
		public const string VIEW_NAME="<!--##=viewName##-->";
		public const string TABLE_NAME="<!--##=tableName##-->";
		public const string DATATABLE_NAME="<!--##=entityName##-->";
		public const string CONNECTION_ID="<!--##=accessorName##-->";
		internal static void S_RefreshCache()
		{
			if(CacheRepository.Instance.CachedDataSet != null)
			{
				CacheRepository.Instance.CachedDataSet.Refresh(DATATABLE_NAME); 
			}
		}
		private static Hashtable PopulateHashtableWithDefaultValues()
		{
			Hashtable ht = new Hashtable();
			object val=null;

			/*<!--##
			foreach(string entityFieldKey in entity.Fields.Keys)
			{
				Entity.Field entityField = entity.Fields[entityFieldKey];
				<%@EntityFieldIncludes%> 
			##-->*/		
					
			//**<!--##=entityFieldName##-->
			/*<!--##
				if(cSharpKeywordDataType=="bool")
				{
				##-->*/
			val=null;
				/*<!--##
				}
				else if(isValueType)
				{
				##-->*/
			val=null;
				/*<!--##
				}
				else
				{
				##-->*/
			val=null;
				/*<!--##
				}
				##-->*/
			ht.Add(FieldNames.<!--##=entityFieldConstant##-->,val);

			/*<!--##
			}
			##-->*/	
			return ht;
		}
		/** Custom Region End **/
<!--##/session##-->
#endregion

#region <!--##session BUZColMembers##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Members.
		//**Construtors
		//for Default Connection
		public <!--##=collectionName##-->():base(){}		
		
		//for Given Connection 
		public <!--##=collectionName##-->(string strConnectionId):base(strConnectionId){}		
		

		//**Methods
		public  <!--##=className##--> CreateNewBusinessObject()
		{
			return new <!--##=className##-->(m_da.Name);
		}
		
		
		public new <!--##=className##-->DataTable FillDataTable(DataSet ds)
		{
			return (<!--##=className##-->DataTable)base.FillDataTable(ds);
		}
		public new <!--##=className##-->DataTable FillDataTable()
		{
			return (<!--##=className##-->DataTable)base.FillDataTable();
		}


		//**Overridden Members
		protected override void RefreshCache()
		{
			<!--##=className##-->.S_RefreshCache();
		}
		protected override object CreateBusinessObject(BusinessObjectPaper boPaper)
		{
			return new <!--##=className##-->(boPaper,m_da);
		}
        protected override object CreateBOPaper(FieldInfoCollection fields)
		{
			return new <!--##=className##-->Paper(fields);
		}
		protected override FieldInfoCollection GetFieldInfoCollection()
		{
			return <!--##=className##-->.FIELDS;
		}
		public override BusinessObjectRelationCollection ChildRelations
		{
			get
			{
				return <!--##=className##-->.CHILD_RELATIONS;
			}
		}
		public override BusinessObjectRelationCollection ParentRelations
		{
			get
			{
				return <!--##=className##-->.PARENT_RELATIONS;
			}
		}
		
		public override string View_Name
		{
			get
			{
				return <!--##=className##-->.VIEW_NAME;
			}
		}
		public override string Table_Name
		{
			get
			{
				return <!--##=className##-->.TABLE_NAME;
			}
		}
		public override string DataTable_Name
		{
			get
			{
				return <!--##=className##-->.DATATABLE_NAME;
			}
		}
		protected override DataTable CreateDataTable()
		{
			return new <!--##=className##-->DataTable();
		}


		protected override void PopulateWithCommandCreators(ref CommandCreatorHandler selectCmdCreator,
			ref CommandCreatorHandler updateCmdCreator,
			ref CommandCreatorHandler insertCmdCreator,
			ref CommandCreatorHandler deleteCmdCreator)
		{
			//can be used later.
			selectCmdCreator = null; //new CommandCreatorHandler(<!--##=className##-->.Create_SelectIDbCommand);
			updateCmdCreator = null; //new CommandCreatorHandler(<!--##=className##-->.Create_UpdateIDbCommand);
			insertCmdCreator = null; //new CommandCreatorHandler(<!--##=className##-->.Create_InsertIDbCommand);
			deleteCmdCreator = null; //new CommandCreatorHandler(<!--##=className##-->.Create_DeleteIDbCommand);
		}
		

		
		//**Properties
		public  <!--##=className##--> BusinessObject
		{
			get
			{
				return base.GetBusinessObject() as <!--##=className##-->; 
			}
		}

		/*<!--##
		foreach(string entityFieldKey in entity.Fields.Keys)
		{
			Entity.Field entityField = entity.Fields[entityFieldKey];
			<%@EntityFieldIncludes%> 
		##-->*/
			/*<!--##
			//binary fields cant be included in where clause. 
			if(dataType!="shortbinary" && dataType!="binary")
			{
				string strNullable = (isValueType)? "?": string.Empty;

			##-->*/
		public <!--##=cSharpKeywordDataType##--><!--##=strNullable##--> <!--##=property##-->
		{
			get
			{
			/*<!--##
			if(isValueType)
			{
			##-->*/
				
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->];
				return (obj != null)?
					(<!--##=cSharpKeywordDataType##-->?)Convert.To<!--##=cSharpFrameworkDataType##-->(obj):
					null;

			/*<!--##
			}
			else
			{
			##-->*/
				
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->];
				<!--##=cSharpKeywordDataType##--> val = (obj != null)?
					obj as <!--##=cSharpKeywordDataType##-->:
					null;
				
				/*<!--##
				if(cSharpKeywordDataType=="string")
				{
				##-->*/
				if(val != null)
				{
					val=val.Trim('%');
				}			
				/*<!--##
				}
				##-->*/
				return val;
				
			/*<!--##
			}
			##-->*/
			}
			set
			{
				/*<!--##
				if(cSharpKeywordDataType=="string")
				{
				##-->*/
				value= "%" + value.Trim() + "%";				
				/*<!--##
				}
				##-->*/
				this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->]= value; 
			}

		}	

				/*<!--##
				if(isRange)
				{
				##-->*/
		public <!--##=cSharpKeywordDataType##--><!--##=strNullable##--> <!--##=property##-->_From
		{
			get
			{
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##--> + Constants.ColumnSuffix.FROM ];
				return (obj != null)?
					(<!--##=cSharpKeywordDataType##-->?)Convert.To<!--##=cSharpFrameworkDataType##-->(obj):
					null;
			
			}

			set
			{
				this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->+Constants.ColumnSuffix.FROM]=value; 
			}
		}
		public <!--##=cSharpKeywordDataType##--><!--##=strNullable##--> <!--##=property##-->_To
		{
			get
			{
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##--> + Constants.ColumnSuffix.TO ];
				return (obj != null)?
					(<!--##=cSharpKeywordDataType##-->?)Convert.To<!--##=cSharpFrameworkDataType##-->(obj):
					null;
		
			}

			set
			{
				this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->+Constants.ColumnSuffix.TO]=value; 
			}
		}
				/*<!--##
				}
				##-->*/
			/*<!--##
			}
			##-->*/
		/*<!--##
		}
		##-->*/	
		

		public override object this[string fieldName]
		{
			get
			{
				string afterTrimed = StringProcessor.RightTrim(fieldName,Constants.ColumnSuffix.TO);
				afterTrimed = StringProcessor.RightTrim(afterTrimed,Constants.ColumnSuffix.TO);

				object obj = base[fieldName];
				return (obj == null)? <!--##=className##-->.DEFAULT_VALUES[afterTrimed]:
					obj;

			}
			set
			{
				base[fieldName]=value;
			}
		}
		
		#endregion


<!--##/session##-->
#endregion

#region <!--##session BUZColCustomCode##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
		//user code should be written under the following region, otherwise code will not be safe.
		/** Custom Region Start [Code Generator] **/
		//Connection Id
		private static string s_connectionId="<!--##=accessorName##-->";
		/** Custom Region End **/
<!--##/session##-->
#endregion

#region <!--##session BUZColWholeClass##-->
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		codeGeneratorVariable_DisplayCode.Append(GeneralUsing() + Environment.NewLine);
		##-->*/
namespace <!--##=RepositoryManager.Instance.Repository.ProjectName##-->.BusinessObjects.<!--##=accessorName##-->
{
	public partial class <!--##=collectionName##-->:BusinessObjectCollection<!--##=iUserLoginImplement##-->
	{
		//Thread based Singleton
		private static <!--##=collectionName##--> singleton;
		public static <!--##=collectionName##--> Instance
		{
			get
			{	<!--##=collectionName##--> col=null;
				if(System.Web.HttpContext.Current != null)
				{
					col= System.Web.HttpContext.Current.Session[<!--##=className##-->.DATATABLE_NAME] as <!--##=collectionName##-->;
				}
				else
				{
					col=singleton;
				}

				if(col == null) 
				{
					col=NewInstance;
					if(System.Web.HttpContext.Current != null)
					{
						System.Web.HttpContext.Current.Session[<!--##=className##-->.DATATABLE_NAME]=col;
					}
					else
					{
						singleton = col;
					}
				}

				
				
				return col;

			}
		}
		public static <!--##=collectionName##--> NewInstance
		{
			get
			{
				<!--##=collectionName##--> instence;
				if(s_connectionId!="") 
                    instence=new <!--##=collectionName##-->(s_connectionId);
				else
					instence=new <!--##=collectionName##-->();	
				
				return instence;

			}
		}

		/*<!--##
		 codeGeneratorVariable_DisplayCode.Append(BUZColMembers() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BUZColCustomCode() + Environment.NewLine);
		##-->*/

		/*<!--##
		if(isUserLoginClass)
		{ 
		##-->*/ 
		#region IUserLogin Members

        public IUser AuthenticateUser(string userId, string password)
        {
            if (!AutoRefresh)
            {
                throw new Exception("AuthenticateUser method requires object, to be set 'AutoRefresh'");
            }
            this.<!--##=StringProcessor.Property(userLogin.UserIdField)##--> = userId;
            <!--##=userClass##--> bo=GetBusinessObject() as <!--##=userClass##-->;
            if (bo == null)
            {
                //authentication failed
                return null;
            }
            else
            {
                //match password
                if ((string.IsNullOrEmpty(bo.<!--##=StringProcessor.Property(userLogin.PasswordField)##-->) && password == userId + "123") || 
					DataEncryptor.Instance.GetDecryptedString(bo.<!--##=StringProcessor.Property(userLogin.PasswordField)##-->).Equals(password))
                {
                    //authentication succeeded.
					if (string.IsNullOrEmpty(bo.<!--##=StringProcessor.Property(userLogin.PasswordField)##-->))
                    {
                        //no password has been assigned, need to assign default password.
                        bo.<!--##=StringProcessor.Property(userLogin.PasswordField)##--> = DataEncryptor.Instance.GetEncryptedString(userId);
                        bo.Save();
                    }
                    return bo as IUser;
                }
                else
                {
                    //authentication failed
                    return null;
                }
            }
        }

        #endregion

		/*<!--##
		} 
		##-->*/ 
		
	}
}
	
<!--##/session##-->
#endregion

#region <!--##session BUZDateTableMembers##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Members.
		
		//**Construtors
		public <!--##=className##-->DataTable():base(<!--##=className##-->.DATATABLE_NAME){DefineDataTable(this);}
		internal <!--##=className##-->DataTable(DataTable table) : 
                base(table.TableName) {
            if ((table.CaseSensitive != table.DataSet.CaseSensitive)) {
                this.CaseSensitive = table.CaseSensitive;
            }
            if ((table.Locale.ToString() != table.DataSet.Locale.ToString())) {
                this.Locale = table.Locale;
            }
            if ((table.Namespace != table.DataSet.Namespace)) {
                this.Namespace = table.Namespace;
            }
            this.Prefix = table.Prefix;
            this.MinimumCapacity = table.MinimumCapacity;
            this.DisplayExpression = table.DisplayExpression;
        }
		
   		
		//**Methods
		public <!--##=className##-->DataRow New<!--##=className##-->DataRow()
		{
			return (<!--##=className##-->DataRow)this.NewRow();
		}
		/*<!--##
		if(keySignature != string.Empty)
		{
		##-->*/
		public <!--##=className##-->DataRow Get<!--##=className##-->ByKey(<!--##=keySignature##-->)
		{
			ArrayList al=new ArrayList();
			<!--##=collectionName##--> col = <!--##=collectionName##-->.NewInstance;
			/*<!--##
			foreach(Entity.Field entityField in entity.PrimaryKey)
			{   
				<%@EntityFieldIncludes%> 
			##-->*/
			al.Add(<!--##=entityFieldVariable##-->);
			/*<!--##
			}
			##-->*/
			return this.Rows.Find(al.ToArray()) as <!--##=className##-->DataRow;
		}
		/*<!--##
			}
		##-->*/
        #region IEnumerable Implementation
		public System.Collections.IEnumerator GetEnumerator()
		{
            return this.Rows.GetEnumerator();
        }
        #endregion
        
        

		//**Overridden Members
		protected override System.Type GetRowType() 
		{
			return typeof(<!--##=className##-->DataRow);
		}
		protected override DataRow NewRowFromBuilder(DataRowBuilder builder) 
		{
			return new <!--##=className##-->DataRow(builder);
		}


		//**Properties
		public <!--##=className##-->DataRow this[int index]
        {
			get
			{
				return (<!--##=className##-->DataRow)this.Rows[index];
			}
        }

        #endregion


<!--##/session##-->
#endregion	 

#region <!--##session BUZDataTableStaticMethods##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Static Methods
		private static void DefineDataTable(DataTable dt)
		{
			//attach values, will be used by cache logic.
			dt.ExtendedProperties.Add(Constants.NEED_TO_REFRESH,true);  
			dt.ExtendedProperties.Add(Constants.CONNECTION_ID,<!--##=className##-->.CONNECTION_ID);
			dt.ExtendedProperties.Add(Constants.VIEW_NAME,<!--##=className##-->.VIEW_NAME);


			DataColumn dc=null;
			ArrayList alPK=new ArrayList();
		/*<!--##
		foreach(string entityFieldKey in entity.Fields.Keys)
		{
			Entity.Field entityField = entity.Fields[entityFieldKey];
			<%@EntityFieldIncludes%> 
		##-->*/

			/*** <!--##=entityFieldName##-->***/ 
			dc=dt.Columns.Add(<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->,
				typeof(<!--##=cSharpKeywordDataType##-->));
			dc.Unique=<!--##=isUnique.ToString().ToLower()##-->;
			/*<!--##
			if(autoIncreament)
			{
			##-->*/
			
			//value is computed by database management system.
			dc.ReadOnly=true;
			dc.AutoIncrement=true;
			dc.AutoIncrementSeed=-10;
			dc.AutoIncrementStep=-1;
			/*<!--##
			}
			
		}
		if(entity.PrimaryKey.Length>0)
		{
		##-->*/
			/***PRIMARY KEY***/
			DataColumn[] pk=new DataColumn[<!--##=entity.PrimaryKey.Length##-->];
			/*<!--##
			for(int i=0; i<entity.PrimaryKey.Length;  i++)
			{
				Entity.Field entityField = entity.PrimaryKey[i];
				<%@EntityFieldIncludes%>
			##-->*/	
			pk[<!--##=i##-->]=dt.Columns[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->];
			/*<!--##
			}
			##-->*/
			dt.PrimaryKey=pk;
		/*<!--##
		}
		##-->*/

		}
        #endregion


<!--##/session##-->
#endregion

#region <!--##session BUZDataTableWholeClass##-->
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		codeGeneratorVariable_DisplayCode.Append(GeneralUsing() + Environment.NewLine);
		##-->*/
namespace <!--##=RepositoryManager.Instance.Repository.ProjectName##-->.DataTables.<!--##=accessorName##-->
{
	public partial class <!--##=className##-->DataTable:DataTable,System.Collections.IEnumerable
	{
		/*<!--##
		 codeGeneratorVariable_DisplayCode.Append(BUZDateTableMembers() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BUZDataTableStaticMethods() + Environment.NewLine);
		##-->*/
	}
	public partial class <!--##=className##-->DataRow:DataRow
	{
		/*<!--##
		 codeGeneratorVariable_DisplayCode.Append(BUZDateRowMembers() + Environment.NewLine);
		##-->*/
	}
}
	
<!--##/session##-->
#endregion

#region <!--##session BUZDateRowMembers##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Members.
		
		//**Construtors
		internal <!--##=className##-->DataRow(DataRowBuilder rb) : base(rb){} 
		
   		
		//**Methods

		//**Properties
		/*<!--##
		foreach(string entityFieldKey in entity.Fields.Keys)
		{
			Entity.Field entityField = entity.Fields[entityFieldKey];
			<%@EntityFieldIncludes%> 
			string strNullable = (isValueType)? "?": string.Empty;
		##-->*/
		public <!--##=cSharpKeywordDataType##--><!--##=strNullable##--> Value_<!--##=property##-->
		{
			get
			{
	
			/*<!--##
			if(isValueType)
			{
			##-->*/
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->];
				return (obj != null)?
					(<!--##=cSharpKeywordDataType##-->?)Convert.To<!--##=cSharpFrameworkDataType##-->(obj):
					null;
			/*<!--##
			}
			else
			{
			##-->*/
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->];
				return (obj != null)?
					obj as <!--##=cSharpKeywordDataType##-->:
					null;
			/*<!--##
			}
			##-->*/
			}
			
			/*<!--##
			if(isNative && !tokenEnabled && !autoIncreament )
			{
			##-->*/
			
			set
			{
				this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->]=value;
			}
			/*<!--##
			}
			##-->*/
		}
			
		/*<!--##
		}
		##-->*/	
				
		#region Relational Properties
		
		#region Children
		/*<!--##
		foreach(string relKey in  entity.Children.Keys)
		{   
			Entity.Relation relation = entity.Children[relKey];
			<%@RelationIncludes%>
			Entity refEntity = relation.ReferencedEntity;
			<%@RefEntityIncludes%>
		##-->*/
		//<!--##=refEntityName##-->
		public <!--##=refClassName##-->DataRow[] Children_<!--##=refClassName##-->
		{
			get
			{
				return ((<!--##=refClassName##-->DataRow[])(base.GetChildRows(this.Table.ChildRelations["<!--##=childRelationName##-->"])));
			}
		}
   		
		/*<!--##
		}
		##-->*/
		#endregion
		
		#region Parents
		/*<!--##
		foreach(string relKey in  entity.Parents.Keys)
		{   
			Entity.Relation relation = entity.Parents[relKey];
			<%@RelationIncludes%>
			Entity refEntity = relation.ReferencedEntity;
			<%@RefEntityIncludes%>
		##-->*/
		//<!--##=refEntityName##-->
		public <!--##=refClassName##-->DataRow Parent_<!--##=refClassName##-->
		{
			get
			{
				return ((<!--##=refClassName##-->DataRow)(base.GetParentRow(this.Table.ParentRelations["<!--##=parentRelationName##-->"])));
			}
			set
            {
                this.SetParentRow(value, this.Table.ParentRelations["<!--##=parentRelationName##-->"]);
            }
		}
		/*<!--##
		}
		##-->*/
   		
		#endregion
		#endregion


		public object this[string fieldName]
		{
			get
			{
				object obj= base[fieldName];
				return (obj ==DBNull.Value)?
					 <!--##=className##-->.DEFAULT_VALUES[fieldName]:
					 obj;
			}
			set
			{
				if(value == null)
				{
					value = DBNull.Value;
				}
				base[fieldName]= value;
			}
		}	
		#endregion

<!--##/session##-->
#endregion	

#region <!--##session BUZPaperMembers##--> 
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		##-->*/
        #region Members.
		//**Construtors
		
		//For current row
		internal <!--##=className##-->Paper(<!--##=className##-->Paper sourcePaper):base(sourcePaper){}
		
		//For new row 
		public  <!--##=className##-->Paper():base(<!--##=className##-->.FIELDS){}
		public  <!--##=className##-->Paper(FieldInfoCollection fields):base(fields){}
		

		//**Properties
		/*<!--##
		foreach(string entityFieldKey in entity.Fields.Keys)
		{
			Entity.Field entityField = entity.Fields[entityFieldKey];
			<%@EntityFieldIncludes%> 
			string strNullable = (isValueType)? "?": string.Empty;
		##-->*/
		public <!--##=cSharpKeywordDataType##--><!--##=strNullable##--> <!--##=property##-->
		{
			get
			{
			/*<!--##
			if(isValueType)
			{
			##-->*/
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->];
				return (obj != null)?
					(<!--##=cSharpKeywordDataType##-->?)Convert.To<!--##=cSharpFrameworkDataType##-->(obj):
					null;
			/*<!--##
			}
			else
			{
			##-->*/
				object obj = this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->];
				return (obj != null)?
					obj as <!--##=cSharpKeywordDataType##-->:
					null;
			/*<!--##
			}
			##-->*/
			}
			
			/*<!--##
			if(isNative && !tokenEnabled && !autoIncreament )
			{
			##-->*/
			
			set
			{
				this[<!--##=className##-->.FieldNames.<!--##=entityFieldConstant##-->]=value;
			}
			/*<!--##
			}
			##-->*/
		}
			
		/*<!--##
		}
		##-->*/	
	
		public override object this[string fieldName]
		{
			get
			{
				object obj = base[fieldName];
				return (obj == DBNull.Value || obj ==null)?
					 <!--##=className##-->.DEFAULT_VALUES[fieldName]:
					 obj;
			}
			set
			{
				base[fieldName]= value;
			}
		}	

		#endregion


<!--##/session##-->
#endregion
